class TalkDialog extends renderer.DisplayObjectContainer {


    private titleText: renderer.TextField;
    private contentText: renderer.TextField;
    private nameText:renderer.TextField;
    private mission: Mission;
    private npc: Npc;
    private headTexture=new Image();
    private HeadTexture:renderer.Bitmap;
    private clickIndex = 0;

    private backGround:renderer.DisplayObjectContainer;
    private UiTexture:renderer.DisplayObjectContainer;

    constructor(npc:Npc) {
        super();

        this.backGround=new renderer.DisplayObjectContainer();
        this.UiTexture=new renderer.DisplayObjectContainer();
        const dialogBackgroundTexture = new Image();
        const Button1Texture=new Image();
        const Button2Texture=new Image();
        Button1Texture.src="3.png";
        Button2Texture.src="4.png";
        dialogBackgroundTexture.src = 'dialog.png';

        this.npc = npc;
        const Button1=new renderer.Bitmap(340,530,Button1Texture);
        const Button2=new renderer.Bitmap(470,530,Button2Texture);
        Button1.scaleX = Button1.scaleY = 0.8;
        Button2.scaleX = Button2.scaleY = 0.8;
        const background = new renderer.Bitmap(28, 400, dialogBackgroundTexture);
        background.scaleX = 2.00;
        background.scaleY = 0.80;
        this.backGround.addChild(background);
        this.nameText = new renderer.TextField();
        this.UiTexture.addChild(this.nameText);
        this.nameText.text = this.npc.name;
        this.nameText.x = 500;
        this.nameText.y = 450;
        this.nameText.size = 13;
        this.nameText.scaleX = this.nameText.scaleY = 1;
        this.UiTexture.addChild(Button1);
        this.UiTexture.addChild(Button2);

        
        this.HeadTexture = new renderer.Bitmap(550, 430,this.headTexture);
        this.UiTexture.addChild(this.HeadTexture);

        this.titleText = new renderer.TextField();
        
        this.UiTexture.addChild(this.titleText);
        this.titleText.x = 100;
        this.titleText.y = 430;
        this.titleText.scaleX = this.titleText.scaleY = 1;
        this.titleText.size = 10;

        this.contentText = new renderer.TextField();
        this.UiTexture.addChild(this.contentText);
        this.contentText.x = 100;
        this.contentText.y = 500;
        this.contentText.size = 13;
        Button1.addEventListener("click", () => {
            this.clickIndex++;
            this.update();
        });
        Button2.addEventListener("click",()=>{
            this.dispatchEvent("close",{});
        });
        this.addChild(this.backGround);
        this.addChild(this.UiTexture);

    }

    update() {
        const mission = this.mission;
        // let content: string[] = [];
        let content1:any="";
        

        this.titleText.text = mission.title;
        if (mission.status == MissionStatus.CAN_ACCEPT) {
            content1 = mission.canAcceptContent.shift();
            

        }
        else if (mission.status == MissionStatus.CAN_SUBMIT) {
            content1 = mission.canSubmitContent.shift();

        }
        if(content1==null){
            console.log(22222);    
            this.dispatchEvent("close",{});
            }else{
                 this.contentText.text =content1.statements;
            // console.log(content1.statements);
            this.headTexture.src=content1.Image;
            this.nameText.text = content1.name;
            }
           
           
        
    }

    setMission(mission: Mission) {
        this.mission = mission;
        this.update();
    }



}